package com.neu.servlet.klz;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.klz.InsertService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "GoodInsertServlet", urlPatterns = {"/GoodInsertServlet.do"})
public class GoodInsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//         Map<String ,String[]> map= request.getParameterMap();
        String k_id=request.getParameter("k_id");
        String e_id=request.getParameter("e_id");
        String g_name=request.getParameter("g_name");
        String g_info=request.getParameter("g_info");
        String g_key=request.getParameter("g_key");
        String g_date=request.getParameter("g_date");
        String g_now=request.getParameter("g_now");
        String g_num=request.getParameter("g_num");
        String g_img=request.getParameter("g_img");
        InsertService insertService=new InsertService();
        boolean flag=insertService.dosave(k_id,e_id,g_name,g_info,g_key,g_date,g_now,g_num,g_img);
//        HttpSession session=request.getSession();
//        session.setAttribute("k_id",k_id);
//        session.setAttribute(" e_id",e_id);
        Map<String,Object> map=new HashMap<>();
        if(flag){
            map.put("msg","添加成功");
            String json=JSONObject.toJSONString(map);
            System.out.println(json);
            PrintWriter out=response.getWriter();
            out.print(json);
            out.close();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
